<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/home', function(){
    return Redirect::to( '/');
});

Route::group(['middleware' => ['auth']], function ($router) {

    $router->get('/', 'TaskController@index');

    Route::group(['middleware' => ['admin.auth']], function ($router) {
        // 项目配置
        $router->group(['prefix' => 'project'], function ($router) {
            $router->post('search', 'ProjectController@index');
            $router->post('detect', 'ProjectController@detect');
        });
        $router->resource('project', 'ProjectController');

        // 用户管理
        $router->group(['prefix' => 'user'], function ($router) {
            $router->post('search', 'UserController@index');
        });
        $router->resource('user', 'UserController');
    });

    // 上线单管理
    $router->group(['prefix' => 'task'], function ($router) {
        $router->post('search', 'TaskController@index');
        $router->get('select', 'TaskController@select');
        $router->post('start-deploy', 'TaskController@StartDeploy');
        $router->get('/deploy/{pid}', 'TaskController@deploy')->where(['pid' => '[0-9]+']);
        $router->get('/create/{pid}', 'TaskController@create')->where(['pid' => '[0-9]+']);
        $router->get('/rollback/{tid}', 'TaskController@rollback')->where(['tid' => '[0-9]+']);
        $router->get('/get-process/{tid}', 'TaskController@GetProcess')->where(['tid' => '[0-9]+']);
    });

    $router->resource('task', 'TaskController');
});

// 认证路由
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// 注册路由
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Auth::routes();